package controller

import (
	"github.com/gin-gonic/gin"
	"go_code/gin-blog/dao/db"
	"go_code/gin-blog/model"
	"go_code/gin-blog/service"
	"log"
	"net/http"
	"time"
)

func LeaveNew(c *gin.Context) {
	leaveList, err := service.GetLeaveList()
	for _, k := range leaveList {
		log.Println(k)
	}
	if err != nil {
		c.HTML(http.StatusInternalServerError, "views/500.html", nil)
	}
	c.HTML(http.StatusOK, "views/gbook.html", leaveList)
}

func AddLeave(c *gin.Context) {
	comment := c.PostForm("comment")
	username := c.PostForm("author")
	leave := &model.Leave{
		Username:    username,
		Content:     comment,
		Create_time: time.Now(),
	}
	flag, _ := db.InsertLeave(leave)
	if !flag {
		c.HTML(http.StatusInternalServerError, "views/500.html", nil)
	}
	LeaveNew(c)
}
